package com.xiaotu.threadMethod;

/**
 * @Author xiaotu
 * @Description //TODO
 * @Date 2022/3/25 16:35
 * @ClassName TestState
 * @Version 1.0
 * 观测线程状态
 **/
public class TestState {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("********");
            }
        }, "线程");
        Thread.State state = thread.getState();
        System.out.println(state.toString());
        thread.start();
        state = thread.getState();
        System.out.println(state.toString());
        while (state != Thread.State.TERMINATED){
            Thread.sleep(200);
            state = thread.getState();
            System.out.println(state.toString());
        }

    }
}
